home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / fuzzyborder.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  5.4 KB  |  166 lines

  1. ;
  2. ; fuzzy-border
  3. ;
  4. ; Do a cool fade to a given colour at the border of an image (optional shadow)
  5. ; Will make image RGB if it isn't already.
  6. ;
  7. ; Chris Gutteridge (cjg@ecs.soton.ac.uk)
  8. ; At ECS Dept, University of Southampton, England.
  9.  
  10. ; This program is free software: you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 3 of the License, or
  13. ; (at your option) any later version.
  14. ;
  15. ; This program is distributed in the hope that it will be useful,
  16. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ; GNU General Public License for more details.
  19. ;
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22.  
  23. ; Define the function:
  24.  
  25. (define (script-fu-fuzzy-border inImage
  26.                                 inLayer
  27.                                 inColor
  28.                                 inSize
  29.                                 inBlur
  30.                                 inGranu
  31.                                 inShadow
  32.                                 inShadWeight
  33.                                 inCopy
  34.                                 inFlatten
  35.         )
  36.  
  37.   (let (
  38.        (theWidth (car (gimp-image-width inImage)))
  39.        (theHeight (car (gimp-image-height inImage)))
  40.        (theImage 0)
  41.        (theLayer 0)
  42.        )
  43.  
  44.     (gimp-context-push)
  45.  
  46.     (gimp-selection-all inImage)
  47.     (set! theImage (if (= inCopy TRUE)
  48.                      (car (gimp-image-duplicate inImage))
  49.                      inImage
  50.                    )
  51.     )
  52.     (if (> (car (gimp-drawable-type inLayer)) 1)
  53.         (gimp-image-convert-rgb theImage)
  54.     )
  55.  
  56.     (set! theLayer (car (gimp-layer-new theImage
  57.                                         theWidth
  58.                                         theHeight
  59.                                         RGBA-IMAGE
  60.                                         "layer 1"
  61.                                         100
  62.                                         NORMAL-MODE)))
  63.  
  64.     (gimp-image-add-layer theImage theLayer 0)
  65.  
  66.  
  67.     (gimp-edit-clear theLayer)
  68.     (chris-color-edge theImage theLayer inColor inSize)
  69.  
  70.     (gimp-layer-scale theLayer
  71.                       (/ theWidth inGranu)
  72.                       (/ theHeight inGranu)
  73.                       TRUE)
  74.  
  75.     (plug-in-spread RUN-NONINTERACTIVE
  76.                     theImage
  77.                     theLayer
  78.                     (/ inSize inGranu)
  79.                     (/ inSize inGranu))
  80.     (chris-color-edge theImage theLayer inColor 1)
  81.     (gimp-layer-scale theLayer theWidth theHeight TRUE)
  82.  
  83.     (gimp-selection-layer-alpha theLayer)
  84.     (gimp-selection-invert theImage)
  85.     (gimp-edit-clear theLayer)
  86.     (gimp-selection-invert theImage)
  87.     (gimp-edit-clear theLayer)
  88.     (gimp-context-set-background inColor)
  89.     (gimp-edit-fill theLayer BACKGROUND-FILL)
  90.     (gimp-selection-none inImage)
  91.     (chris-color-edge theImage theLayer inColor 1)
  92.  
  93.     (if (= inBlur TRUE)
  94.         (plug-in-gauss-rle RUN-NONINTERACTIVE
  95.                theImage theLayer inSize TRUE TRUE)
  96.     )
  97.     (if (= inShadow TRUE)
  98.         (begin
  99.           (gimp-selection-none inImage)
  100.           (gimp-image-add-layer theImage
  101.                                 (car (gimp-layer-copy theLayer FALSE)) 0)
  102.           (gimp-layer-scale theLayer
  103.                             (- theWidth inSize) (- theHeight inSize) TRUE)
  104.           (gimp-desaturate theLayer)
  105.           (gimp-brightness-contrast theLayer 127 127)
  106.           (gimp-invert theLayer)
  107.           (gimp-layer-resize theLayer
  108.                              theWidth
  109.                              theHeight
  110.                              (/ inSize 2)
  111.                              (/ inSize 2))
  112.           (plug-in-gauss-rle RUN-NONINTERACTIVE
  113.                              theImage
  114.                              theLayer
  115.                              (/ inSize 2)
  116.                              TRUE
  117.                              TRUE)
  118.           (gimp-layer-set-opacity theLayer inShadWeight)
  119.         )
  120.     )
  121.     (if (= inFlatten TRUE)
  122.         (gimp-image-flatten theImage)
  123.     )
  124.     (if (= inCopy TRUE)
  125.       (begin
  126.         (gimp-image-clean-all theImage)
  127.         (gimp-display-new theImage)
  128.       )
  129.     )
  130.     (gimp-displays-flush)
  131.  
  132.     (gimp-context-pop)
  133.   )
  134. )
  135.  
  136. (define (chris-color-edge inImage inLayer inColor inSize)
  137.   (gimp-selection-all inImage)
  138.   (gimp-selection-shrink inImage inSize)
  139.   (gimp-selection-invert inImage)
  140.   (gimp-context-set-background inColor)
  141.   (gimp-edit-fill inLayer BACKGROUND-FILL)
  142.   (gimp-selection-none inImage)
  143. )
  144.  
  145. (script-fu-register "script-fu-fuzzy-border"
  146.   _"_Fuzzy Border..."
  147.   _"Add a jagged, fuzzy border to an image"
  148.   "Chris Gutteridge"
  149.   "1998, Chris Gutteridge / ECS dept, University of Southampton, England."
  150.   "3rd April 1998"
  151.   "RGB* GRAY*"
  152.   SF-IMAGE      "The image"               0
  153.   SF-DRAWABLE   "The layer"               0
  154.   SF-COLOR      _"Color"                  "white"
  155.   SF-ADJUSTMENT _"Border size"            '(16 1 300 1 10 0 1)
  156.   SF-TOGGLE     _"Blur border"            TRUE
  157.   SF-ADJUSTMENT _"Granularity (1 is Low)" '(4 1 16 0.25 5 2 0)
  158.   SF-TOGGLE     _"Add shadow"             FALSE
  159.   SF-ADJUSTMENT _"Shadow weight (%)"      '(100 0 100 1 10 0 0)
  160.   SF-TOGGLE     _"Work on copy"           TRUE
  161.   SF-TOGGLE     _"Flatten image"          TRUE
  162. )
  163.  
  164. (script-fu-menu-register "script-fu-fuzzy-border"
  165.                          "<Image>/Filters/Decor")
  166.